<?php

declare(strict_types=1);

namespace app\common\model\Project;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @mixin \think\Model
 */
class Order extends Model
{
    // 预约订单表
    protected $table = 'pre_project_order';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    // 定义创建时间
    protected $createTime = 'createtime';
    // 定义更新时间
    protected $updateTime = false;
    // 使用软删除
    use SoftDelete;
    // 软删除字段
    protected $deleteTime = 'deletetime';
    // 追加字段
    protected $append = [
        'status_text'
    ];

    public function getStatusTextAttr($value, $data)
    {
        $status_text = '';

        switch ($data['status']) {
            case 0:
                $status_text = '未接单';
                break;

            case 1:
                $status_text = '已接单';
                break;

            case 2:
                $status_text = '已付款';
                break;

            case 3:
                $status_text = '已完成';
                break;

            case -1:
                $status_text = '已撤销';
                break;

            case -2:
                $status_text = '撤销中';
                break;

            case -3:
                $status_text = '拒绝撤销';
                break;
        }
        return $status_text;
    }
    // 关联查询
    public function project()
    {
        return $this->belongsTo('app\common\model\Project\Project', 'projectid', 'id');
    }
    public function user()
    {
        return $this->belongsTo('app\common\model\User\User', 'userid', 'id');
    }
    public function address()
    {
        return $this->belongsTo('app\common\model\User\Address','addrid','id');
    }
}
